/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.sree.tali.actions;

import com.sree.tali.buscomp.ShowArticleBusComp;
import com.sree.tali.buscomp.ShowArticleBusCompImpl;
import com.sree.tali.plugin.HibernatePlugin;
import com.sree.tali.pojo.UploadImagePojo;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.actions.DispatchAction;
import org.hibernate.SessionFactory;

/**
 *
 * @author sreenuv
 */
public class ShowArticles  extends DispatchAction {
    
    
  public ActionForward showArticle(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response)
    throws Exception
  {
      ShowArticleBusComp buscomp = new ShowArticleBusCompImpl();
      SessionFactory localSessionFactory = (SessionFactory)this.servlet.getServletContext().getAttribute(HibernatePlugin.KEY_NAME);
      if(localSessionFactory!=null){
      List<UploadImagePojo> homearticles = buscomp.showHomeArticle(localSessionFactory.openSession());
      request.setAttribute("homearticles", homearticles);
      }
      return mapping.findForward("homepage");
      
  }
  
   public ActionForward displayArticle(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response)
    throws Exception
  {
      String articleType = request.getParameter("articleName");
      ShowArticleBusComp buscomp = new ShowArticleBusCompImpl();
      SessionFactory localSessionFactory = (SessionFactory)this.servlet.getServletContext().getAttribute(HibernatePlugin.KEY_NAME);
      UploadImagePojo uploadhomeimage = buscomp.showArticle(localSessionFactory.openSession(),articleType );
      List<UploadImagePojo> reltedArticles = buscomp.showRelatedArticle(localSessionFactory.openSession() ,uploadhomeimage);
      List<UploadImagePojo> recentArticles = buscomp.showRecentArticle(localSessionFactory.openSession() ,uploadhomeimage);
      List<UploadImagePojo> mostViewedArticles = buscomp.showMostViewedArticle(localSessionFactory.openSession() ,uploadhomeimage);
      request.setAttribute("uploadhomeimage", uploadhomeimage);
      request.setAttribute("reltedArticles", reltedArticles);
      request.setAttribute("recentArticles", recentArticles);
      request.setAttribute("mostViewedArticles", mostViewedArticles);
      return mapping.findForward("commonpage");
  }
   
    public ActionForward displayTitles(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response)
    throws Exception
  {
      String articleType = request.getParameter("articleType");
      ShowArticleBusComp buscomp = new ShowArticleBusCompImpl();
      SessionFactory localSessionFactory = (SessionFactory)this.servlet.getServletContext().getAttribute(HibernatePlugin.KEY_NAME);
      List<UploadImagePojo> homearticles = buscomp.showTitles(localSessionFactory.openSession(),articleType );
      request.setAttribute("homearticles", homearticles);
      return mapping.findForward("titlespage");
  }
    
    
    
}
